<!--内部转账验证-->
<template>
  <div class="bg bg1">
    
    <div class="height60"></div>
    <text class="font60 text2">{{phone?T('手机验证'):T('邮箱验证')}}</text>

    <div class="height60"></div>
    <div class="row">
      <input class="input font30 text2 all" v-model="smsCode" type="number" :placeholder="T('验证码')" maxlength="9" @input="onInput">
      <div class="send main-b1" @click="verifiCilci">
        <text class="fongt26 main-t1">{{time==0?T('发送验证码'):time+" S"}}</text>
      </div>
    </div>
    <div class="line line1"></div>

    <div class="ok main-bt1" @click="okClick">
      <text class="font30 text1">{{T('确认')}}</text>
    </div>
  </div>
</template>

<style src="@/_css/style.css" ></style>
<style scoped>
.bg {
  flex: 1;
  padding-left: 40px;
  padding-right: 40px;
}
.input{
  height: 80px;
  placeholder-color:#6E7488; 
  margin-top: 10px;
}
.line{
  height:1px;
}
.send {
  justify-content: center;
  align-items: center;
  height:70px;
  border-radius:12px;

  border-width: 1px;

  padding-left: 30px;
  padding-right: 30px;
}
.ok {
  justify-content: center;
  align-items: center;
  height:72px;
  border-radius:12px;
  margin-top: 120px;
}
</style>

<script>

import jnavigator from "@/_js/navigator";
import jmodal from "@/_js/modal";
import jmath from "@/_js/math";
import jhttps from "@/_js/https";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T('转账验证'));

export default {
  
  data() {
    return {
      T:T,      
      time:0, //倒计时

      wallet:undefined, //consumeWallet(消费钱包) incomeWallet(收益钱包) depositWallet(保证金钱包)

      areaCode:"",  //手机区号
      phone:"", //手机
      email:"", //邮箱
      smsCode:"", //验证码
      
      coinType:"", //转账币
      toAddress:"", //转账UID
      remark:"", //备注
      amount:"", //转账数量

      quity:true, //true-含提现权益
    };
  },

  mounted() {
    var param = weex.config;
    this.wallet =  param.wallet;

    this.areaCode =  param.areaCode;
    this.phone =  param.phone;
    this.email =  param.email;

    this.coinType =  param.coinType;
    this.toAddress =  param.toAddress;
    this.remark =  param.remark;
    this.amount =  param.amount;
    this.quity =  param.quity;
  },

  methods: {
    
    /************************************************* HTTP*/
    //http确转账
    httpsTransferOK(){

      jmodal.showLoad();
      var param = {'wallet':this.wallet,
                  'toAddress':this.toAddress, 
                  'remark':this.remark, 
                  'amount':this.amount, 
                  'coinType':this.coinType, 
                  'smsCode':this.smsCode, 
                  'isVtnEquity':this.quity};
      if (!this.phone) {
        param['email'] = this.email;
      } else {
        param['phone'] = this.phone;
        param['areaCode'] = this.areaCode;
      }
      jhttps.postGa("tradeV2/innerTransfer",param,true,(data)=>{
        jmodal.hideLoad();
        if(data.status == 200){
          jmodal.toast(T('转账成功'));
          jnavigator.back(2);
        }else{
          jmodal.toast(data.msg);
        }
      });
    },

    /************************************************* 其他*/
    //倒计时
    timeDown(time,callback){
      var tick = function(){
        setTimeout(() => {
          time--;
          callback(time);
          if(time > 0){
            tick();
          }
        }, 1000);
      };
      tick();
    },
    
    /************************************************* 点击*/
    //获取验证码
    verifiCilci(){
      
      if(this.time > 0){
        return;
      }

      weexFunction.showVerifiSMS(this.email,this.phone,this.areaCode,"TRANSFER_OUT",(e)=>{
        this.time=30;
        this.timeDown(30,(e)=>{
          this.time=e;
        });
      });
    },

    //确定
    okClick(){
      if(this.smsCode.length == 0){
        modal.toast(T('请输入验证码'));
      } else {
        this.httpsTransferOK();
      }
    },
  },
}
</script>
